//异步函数两种方法
// const name = async (params) => {}
// async function name(params) {}
import {message} from "antd";
import request from 'umi-request';

export const getRemoteList = async () => {
  return request('/api/transaction-detail/all', {
    method: 'get',
    // params: { id: 1 },
  })
    .then(function(response) {
      console.log("getAll后端返回response!!",response);
      return response.data;
    })
    .catch(function(error) {
      message.error("获得列表数据失败");
    });
}

export const getPageInfoList = async (pageNum, pageSize) => {
  return request(`/api/transaction-detail/paging?page=${pageNum}&size=${pageSize}`, {
    method: 'get',
    // params: { id: 1 },
  })
    .then(function(response) {
      console.log("getPageInfoList后端返回response!!",response);
      return response.data;
    })
    .catch(function(error) {
      message.error("获得分页列表数据失败");
    });
}

export const editRemote = async (id, values) => {
  return request(`/api/transaction-detail/edit/${id}`, {
    method: 'put',
    data: values,
  })
    .then(function(response) {
      console.log("编辑APi后端返回response!!",response);
      message.success("编辑成功！");
      return response.data;
    })
    .catch(function(error) {
      message.error("编辑失败");
    });
}

export const deleteTransaction = async (id) => {
  return request(`/api/transaction-detail/delete/${id}`, {
    method: 'delete',
  })
    .then(function(response) {
      console.log("删除APi后端返回response");
      message.success("删除成功！");
      return response.data;
    })
    .catch(function(error) {
      message.error("删除失败");
    });
}

export const createTransaction = async ( values) => {
  return request(`/api/transaction-detail/create`, {
    method: 'post',
    data: values,
  })
    .then(function(response) {
      console.log("新建APi后端返回response");
      message.success("添加成功！");
      return response.data;
    })
    .catch(function(error) {
      message.error("新建失败");
    });
}


